package com.zecan.blog.controller;

import com.zecan.blog.common.BlogResult;
import com.zecan.blog.service.BlogUserService;
import com.zecan.blog.service.FriendService;
import com.zecan.blog.utils.BlogResultUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zecan
 * @Description:
 * @ClassName: FriendController
 * @date 2022/12/18 14:04
 */

@RestController()
@RequestMapping("/friend")
public class FriendController {

    @Resource
    private FriendService friendService;


    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @PreAuthorize("hasAuthority('user') OR hasAuthority('admin')" )
    public BlogResult getUserFriend(Integer userId) {

        return BlogResultUtils.ok(friendService.getUserFriendList(userId),"获取用户好友列表成功");
    }

    @PreAuthorize("hasAuthority('user') OR hasAuthority('admin')" )
    @RequestMapping(value = "/user_list",method = RequestMethod.POST)
    public BlogResult getUser(){
        return BlogResultUtils.ok(friendService.getAllUser(),"获取用户列表成功");
    }


    @PreAuthorize("hasAuthority('user') OR hasAuthority('admin')" )
    @RequestMapping(value = "/add_friend",method = RequestMethod.POST)
    public BlogResult addFriend(Integer sendAddUserId, Integer addUserId){
        friendService.addFriend(sendAddUserId, addUserId);
        return BlogResultUtils.ok("添加好友成功");
    }
}
